{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.1 What is concurrency?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Concurrency in computer systems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "At the simplest and most basic level, **concurrency** is about two or more separate activities happening at the same time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**task switching**: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**hardware concurrency**:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**context switch**:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Two approaches to concurrency: parallel execution on a dual-core machine versus task switching on a single-core machine\n",
    "\n",
    "<img src=\"./images/1.1.png\" alt=\"Figure 1.1\" style=\"zoom:50%;\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**hardware threads**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Task switching of four tasks on two cores\n",
    "\n",
    "<img src=\"./images/1.2.png\" alt=\"Figure 1.2\" style=\"zoom:50%;\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Approaches to concurrency"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Concurrency with Multiple Processes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Communication between a pair of processes running concurrently\n",
    "\n",
    "<img src=\"./images/1.3.png\" alt=\"Figure 1.3\" style=\"zoom:50%;\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Concurrency with Multiple Threads"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Communication between a pair of threads running concurrently in a single process\n",
    "\n",
    "<img src=\"./images/1.4.png\" alt=\"Figure 1.4\" style=\"zoom:50%;\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Concurrency vs. parallelism"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **parallelism** : People talk about parallelism when their primary concern is taking advantage of the available hardware to increase the performance of bulk data processing\n",
    "- **concurrency** : people talk about concurrency when their primary concern is separation of concerns, or responsiveness."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.2 Why use concurrency?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two main reasons to use concurrency in an application: **separation of concerns** and **performance.**"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "name": "C++17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
